﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;
using System.Data.SqlClient;
using System.Configuration;

namespace BHair
{
    public partial class frmcj2000 : Form
    {
        public frmcj2000()
        {
            InitializeComponent();
        }
        string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
        private void button1_Click(object sender, EventArgs e)
        {
            string lujing = AppDomain.CurrentDomain.BaseDirectory;
            string basename = "BHairDB";
           
                excutesqlfile("sa", "", "BHairDB", lujing,"127.0.0.1");
              
            
        }
      

       

      
        public static void excutesqlfile(string user, string pwd, string databasename, string targetdir,string ser)
        {
            try
            {
                System.Diagnostics.Process sqlProcess = new System.Diagnostics.Process();
                sqlProcess.StartInfo.FileName = "osql.exe ";
                sqlProcess.StartInfo.Arguments = " -U " + user + " -P " + pwd+" -S " + ser + " -i " + targetdir + "20170326.sql";
                sqlProcess.StartInfo.UseShellExecute = false;
                sqlProcess.StartInfo.RedirectStandardOutput = true; //重定向输出
                sqlProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                sqlProcess.Start();
                System.IO.StreamReader sr = sqlProcess.StandardOutput;
                Console.WriteLine(sr.ReadToEnd());
                sqlProcess.WaitForExit();//程序安装过程中执行
                sqlProcess.Close();
                MessageBox.Show("ok");
            }
            catch (Exception ex1) 
            {
                MessageBox.Show(ex1.Message);
            }
        }
    }
        
}
